package com.front.teacher.teacherapp.view.activity;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.front.teacher.teacherapp.R;
import com.front.teacher.teacherapp.base.BaseActivity;
import com.front.teacher.teacherapp.utils.AESUtils;
import com.front.teacher.teacherapp.utils.BottomTabManager;
import com.front.teacher.teacherapp.view.fragment.ActivityFragment;
import com.front.teacher.teacherapp.view.fragment.EvaluateFragment;
import com.front.teacher.teacherapp.view.fragment.EvidenceFragment;
import com.front.teacher.teacherapp.view.fragment.MineFragment;

import java.util.ArrayList;

import butterknife.InjectView;

public class MainActivity extends BaseActivity implements BottomTabManager.OnBottomTabSelectListener {
    private Context mContext = this;
    @InjectView(R.id.frame_main)
    FrameLayout frameMain;
    @InjectView(R.id.radiogroup_bottom_main)
    RadioGroup radiogroupBottomMain;
    @InjectView(R.id.bottom_evaluate_rbtn)
    RadioButton bottomEvaluateRbtn;
    @InjectView(R.id.bottom_evidence_rbtn)
    RadioButton bottomEvidenceRbtn;
    @InjectView(R.id.bottom_activity_rbtn)
    RadioButton bottomActivityRbtn;
    @InjectView(R.id.bottom_mine_rbtn)
    RadioButton bottomMineRbtn;

    @Override
    public void initView() {
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(EvaluateFragment.newInstance());
        fragments.add(EvidenceFragment.newInstance());
        fragments.add(ActivityFragment.newInstance());
        fragments.add(new MineFragment());

        //这里可以设置radiobutton的图片大小
        Drawable drawable1 = getResources().getDrawable(R.drawable.evidence_selector);
        drawable1.setBounds(0, 0, 40, 40);//第一0是距左右边距离，第二0是距上下边距离，第三69长度,第四宽度
        bottomEvidenceRbtn.setCompoundDrawables(null, drawable1, null, null);//只放上面
        Drawable drawable2 = getResources().getDrawable(R.drawable.evaluate_selector);
        drawable2.setBounds(0, 0, 40, 40);
        bottomEvaluateRbtn.setCompoundDrawables(null, drawable2, null, null);
        Drawable drawable3 = getResources().getDrawable(R.drawable.activity_selector);
        drawable3.setBounds(0, 0, 40, 40);
        bottomActivityRbtn.setCompoundDrawables(null, drawable3, null, null);
        Drawable drawable4 = getResources().getDrawable(R.drawable.mine_selector);
        drawable4.setBounds(0, 0, 40, 40);
        bottomMineRbtn.setCompoundDrawables(null, drawable4, null, null);
        new BottomTabManager(fragments, radiogroupBottomMain, getSupportFragmentManager(), R.id.frame_main, this);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void onBottomTabSelectListener(RadioGroup group, int checkedId, int index) {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode){
            case KeyEvent.KEYCODE_BACK:
                showDialog("您真的要退出吗？");
                break;
        }
        return super.onKeyDown(keyCode, event);
    }


}
